/*
 * @Author: 0x9DEFA478
 * @Date: 2021-10-18 21:06:09
 * @LastEditTime: 2022-08-11 00:05:08
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "H_Printf.h"
#include <Windows.h>




HANDLE _Mutex;
void* _Buffer;
int _BufferSize;
void (*_PrintfOutput)(void*,int);




//不要单独调用, 这个是为 宏H_Printf_USART 用的
void* H_Printf_USART_CallBeforeFormat(void){
  WaitForSingleObject(_Mutex,INFINITE);
  return _Buffer;
}

//不要单独调用, 这个是为 宏H_Printf_USART 用的
void H_Printf_USART_CallAfterFormat(int Length){

  if(Length>_BufferSize){
    Length=_BufferSize;
  }

  _PrintfOutput(_Buffer,Length);

  ReleaseMutex(_Mutex);
}



//打印端口初始化
void H_Printf_Init(void* Buffer,int BufferSize,void (*PrintfOutput)(void*,int)){

  _Buffer=Buffer;
  _BufferSize=BufferSize;
  _PrintfOutput=PrintfOutput;

  _Mutex=CreateMutex(NULL,FALSE,NULL);
  
}



